<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ page import="com.fengke.csc.config.HostConfig" %>
<%
	HostConfig hostConfig = (HostConfig) request.getSession().getServletContext().getAttribute("hostConfig");
%>
<!DOCTYPE html>
	<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
	<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
	<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
	<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
	<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"><!--<![endif]-->
<head>
	<title><%=hostConfig.getWebSiteName() %></title>
	<meta name="keywords" content="<%=hostConfig.getWebSiteName() %>" />
	<meta name="description" content="<%=hostConfig.getWebSiteName() %>" />
	<jsp:include page="../gadget/include_header.jsp"></jsp:include>
	<style>
		.tip_info {margin-left: 15px;}
		.col-sm-3 {width: 15%;}
		.col-sm-9 {width: 85%;}
		.btn.active {display: inline-block}
		.date-remove{cursor: pointer; background-color: rgb(251, 113, 66); border-radius: 100%; font-weight: normal; height: 17px; line-height: 15px; position: absolute; top: 6px; text-align: center; text-decoration: none; color: rgb(255, 255, 255); right: -20px; width: 17px; font-size: 11px;}
		a.date-remove:HOVER {text-decoration: none;color: #fff;}
	</style
</head>
<body>
	<!-- 头信息 Start -->
	<jsp:include page="../gadget/main_header.jsp"></jsp:include>
	<!-- 头信息 End -->
	<jsp:include page="../gadget/main_sidebar.jsp"></jsp:include>
	<div class="main-content">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed');}catch(e){}
			</script>

			<ul class="breadcrumb">
				<li>
					<i class="icon-home home-icon"></i>
					<a href="#">首页</a>
				</li>
				<li class="active"><s:property value="getText('product.type.' + productVO.productModel.productType)" />管理</li>
			</ul><!-- .breadcrumb -->
		</div>
		<div class="page-content">
			<div class="page-header">
				<h1>
					<s:if test='"create".equals(#request.actionType)'>
						添加<s:property value="getText('product.type.' + productVO.productModel.productType)" />
					</s:if>
					<s:elseif test='"update".equals(#request.actionType)'>
						更新<s:property value="getText('product.type.' + productVO.productModel.productType)" />
					</s:elseif>
					<s:else>
						<s:property value="getText('product.type.' + productVO.productModel.productType)" />信息
					</s:else>
					<small>
						<i class="icon-double-angle-right"></i>
						 查看
					</small>
				</h1>
			</div><!-- /.page-header -->
			<div class="row">
				<div class="col-xs-12">
					<!-- PAGE CONTENT BEGINS -->

					<jsp:include page="../gadget/include_pageMessage.jsp"></jsp:include>
					
					<div class="row-fluid">
						<div class="span12">
							<div class="widget-box">
								<div class="widget-header widget-header-blue widget-header-flat">
									<h4 class="lighter">
										<s:if test='"create".equals(#request.actionType)'>
											新增
										</s:if>
										<s:elseif test='"update".equals(#request.actionType)'>
											更新
										</s:elseif>
										<s:else>
											查看
										</s:else>
									</h4>
								</div><!-- widget-header -->
								
								<s:if test="0 == productVO.productModel.mproductType">
									<jsp:include page="editMerchandise.jsp"></jsp:include>
								</s:if>
								<s:elseif test="1 == productVO.productModel.mproductType">
									<jsp:include page="editActivities.jsp"></jsp:include>
								</s:elseif>
								<s:else>
									<div>关键参数为空！productType is null</div>
								</s:else>
								
							</div><!-- end class="widget-box" -->
						</div><!-- end class="span12" -->
					</div><!-- end class="row-fluid" -->
				</div>
			</div>
		</div>
	</div>
<jsp:include page="../gadget/include_script.jsp"></jsp:include>
<script type="text/javascript">
var mproductType = '<s:property value="productVO.productModel.mproductType" />';
jQuery(function($) {
	$('#sidebar_product').addClass('open');
	$('#sidebar_product').addClass('active');
	if(mproductType == 0) {
		$('#sidebar_product_manager').addClass('active');
	} else if(mproductType == 1) {
		$('#sidebar_activities_manager').addClass('active');
	} else {
		alert('关键参数缺失！productType is null');
	}
});
function init_ace_checkbox(id) {
	$('#' + id + '_box').removeAttr('checked').on('click', function(){
		$('#' + id).attr('value', this.checked);
	});
}
var startingDate_num = -1;
function addStartingDate() {
	startingDate_num++;
	var re = new RegExp("LY","g");
	$('#startingDate_div').append($('#startingDate_example').html().replace(re, startingDate_num));
	$('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
		$(this).prev().focus();
	});
}
function removeStartingDate(obj) {
	$(obj).parent().remove();
}
var productImages_num = -1;
function addProductImages() {
	productImages_num ++;
	$('#productImages_div').append('<input type="file" name="productVO.productImages[' + productImages_num + '].file" id="product_productImages_' + productImages_num + '" class="product_productImages" />');
	init_ace_file_input('#product_productImages_' + productImages_num);
}
</script>
<s:if test="productVO.productModel.mproductType == 0">
	<script type="text/javascript">
	jQuery(function($) {
		$(".select2").css('width','200px').select2({allowClear:true}).on('change', function(){
			$(this).closest('form').validate().element($(this));
		});
		
		init_ace_file_input('#product_image , .product_productImages');
		
		init_ace_wysiwyg('#product_introduction_div');
	
		init_ace_wysiwyg('#product_productFeatures_div');
		
		init_ace_wysiwyg('#product_feeInclude_div');
		
		init_ace_wysiwyg('#product_introduction1_div');
		
		init_ace_wysiwyg('#product_visaInfo_div');
		
		init_ace_wysiwyg('#product_flightInfo_div');
		
		init_ace_wysiwyg('#product_hotelInfo_div');
		
		init_ace_wysiwyg('#product_feeInclude1_div');
		
		$('#product_isMarketable_box').removeAttr('checked').on('click', function(){
			$('#product_isMarketable').attr('value', this.checked);
		});
		$('#product_isTop_box').removeAttr('checked').on('click', function(){
			$('#product_isTop').attr('value', this.checked);
		});
		
		function validStartingDate() {
			if(startingDate_num < 0) {
				addStartingDate();
				$('#startingDate_0').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			var startingDate_str = '';
			for(var i = 0; i <= startingDate_num; i ++) {
				if($.trim($('#startingDate_' + i).val()) != '') {
					if(startingDate_str != '') {
						startingDate_str += ',';
					}
					startingDate_str += $('#startingDate_' + i).val();
				}
			}
			if($.trim(startingDate_str) != '') {
				$('#product_startingDate').attr('value', startingDate_str);
				$('#startingDate_0').closest('.form-group').removeClass('has-error').addClass('has-info');
				return true;
			}
			$('#startingDate_0').closest('.form-group').removeClass('has-info').addClass('has-error');
			return false;
		}
		function validProductImages() {
		<s:if test='"create".equals(#request.actionType)'>
			if(productImages_num < 0) {
				addProductImages();
				$('#product_productImages_0').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			var hasImages = false;
			for(var i = 0; i <= productImages_num; i++) {
				if($('#product_productImages_' + i).val() != null) {
					$('#product_productImages_0').closest('.form-group').removeClass('has-error').addClass('has-info');
					hasImages = hasImages || true;
				} else {
					hasImages = hasImages || false;
				}
			}
			return hasImages;
		</s:if>
		<s:else>
			return true;
		</s:else>
		}
		/*
		function validProductItems() {
			if(productItems_num < 0) {
				addProductItems();
				$('#productItem_0_introduction').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			var hasProductItem = false;
			var hasIntroduction = true;
			for(var i = 0; i <= productItems_num; i ++) {
				if($('#accordion_productItems_' + i).html()) {
					hasProductItem = hasProductItem || true;
					var html = $('#productItem_' + i + '_introduction_div').html();
					if($.trim(html) == '') {
						$('#productItem_' + i + '_introduction').closest('.form-group').removeClass('has-info').addClass('has-error');
						hasIntroduction = hasIntroduction && false;
					} else {
						$('#productItem_' + i + '_introduction').closest('.form-group').removeClass('has-error').addClass('has-info');
					}
				}
			}
			
			if(!hasProductItem) {
				addProductItems();
				$('#productItem_0_introduction').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			//alert(hasProductItem + ", " + hasIntroduction);
			return hasIntroduction && hasProductItem;
		}
		*/
		/*
		function validAdminStorys() {
			if(adminStorys_num < 0) {
				addAdminStorys();
				$('#adminStory_0_content').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			var hasContent = true;
			for(var i = 0; i <= adminStorys_num; i ++) {
				var html = $('#adminStory_' + i + '_content_div').html();
				if($.trim(html) == '') {
					$('#adminStory_' + i + '_content').closest('.form-group').removeClass('has-info').addClass('has-error');
					hasContent = hasContent && false;
				} else {
					$('#adminStory_' + i + '_content').closest('.form-group').removeClass('has-error').addClass('has-info');
				}
			}
			return hasContent;
		}
		*/
		var $validation = true;
		$('#fuelux-wizard').ace_wizard().on('change' , function(e, info){
			if(info.step == 1 && $validation) {
				// step 1
				var validResult = $('#csc_product_edit_form').valid();
				validResult = validStartingDate() && validResult;
				validResult = validProductImages() && validResult;
				if(!validResult) {
					return false;
				} else {
					/*
					if(productItems_num < 0) {
						addProductItems();
					}*/
					return true;
				}
			}
			/*// 行程
			else if(info.step == 2 && $validation) {
				// step 2
				if(validProductItems()) {
					//if(adminStorys_num < 0) {
					//	addAdminStorys();
					//}
					return true;
				} else {
					return false;
				}
			}*/
			/*// 商家故事
			else if(info.step == 3 && $validation) {
				// step 3
				var validResult = validAdminStorys();
				validResult = $('#csc_product_edit_form').valid() && validResult;
				return validResult;
			}
			*/
		}).on('finished', function(e) {
			//$('#csc_product_search_form').submit();
			// 拼装StartingDate
			//product_startingDate
			if(startingDate_num < 0) {
				alert("请输入出发时间！");
				return false;
			}
			<s:if test='"create".equals(#request.actionType)'>
			if(productImages_num < 0) {
				alert("请最少上传一张轮播图！");
				return false;
			}
			</s:if>
			// 处理Step1富文本编辑器
			$('#product_introduction').text($('#product_introduction_div').html());
			$('#product_productFeatures').text($('#product_productFeatures_div').html());
			$('#product_feeInclude').text($('#product_feeInclude_div').html());
			// 处理Step2富文本编辑器
			$('#product_introduction1').text($('#product_introduction1_div').html());
			$('#product_visaInfo').text($('#product_visaInfo_div').html());
			$('#product_flightInfo').text($('#product_flightInfo_div').html());
			$('#product_hotelInfo').text($('#product_hotelInfo_div').html());
			$('#product_feeInclude1').text($('#product_feeInclude1_div').html());
			// 产品标签
			var imageHeads = $('input[name="imageHead"]:checked');
			var descInfos = $('input[name="descInfo"]:checked');
			var tagHtml = '';
			var tagIndex = -1;
			if(imageHeads != null) {
				for(var i = 0; i < imageHeads.length; i ++) {
					tagIndex ++;
					tagHtml += '<input type="hidden" name="productVO.productTags[' + tagIndex + '].tagModel.id" value="' + $(imageHeads[i]).attr('value') + '" />';
				}
			}
			if(descInfos != null && descInfos.length > 0) {
				for(var i = 0; i < descInfos.length; i ++) {
					tagIndex ++;
					tagHtml += '<input type="hidden" name="productVO.productTags[' + tagIndex + '].tagModel.id" value="' + $(descInfos[i]).attr('value') + '" />';
				}
			}
			if($.trim(tagHtml) != '') {
				$('#tag_input_div').html(tagHtml);
			}
			
			/*
			for(var i = 0; i <= productItems_num; i++) {
				if($('#accordion_productItems_' + i).html()) {
					$('#productItem_' + i + '_introduction').text($('#productItem_' + i + '_introduction_div').html());
				}
			}
			*/
			// 处理Step3富文本编辑器
			//for(var i = 0; i <= adminStorys_num; i++) {
			//	$('#adminStory_' + i + '_content').text($('#adminStory_' + i + '_content_div').html());
			//}
			// 提交表单
			$('#csc_product_edit_form').submit();
			/**
			bootbox.dialog({
				message: "Thank you! Your information was successfully saved!", 
				buttons: {
					"success" : {
						"label" : "OK",
						"className" : "btn-sm btn-primary"
					}
				}
			});
			**/
		}).on('stepclick', function(e){
			alert(e);
			//return false;//prevent clicking on steps
		});
		
		$.validator.methods.checkStartingDate = function(value, element, param){
			return validStartingDate();
		};
		
		$.validator.methods.checkProductImages = function(value, element, param){
			return validProductImages();
		};
		
		$('#csc_product_edit_form').validate({
			errorElement: 'div',
			errorClass: 'help-block',
			focusInvalid: false,
			rules: {
				"productVO.productModel.productCategoryModel.id" : {
					required: true
				},
				"productVO.productModel.fullName" : {
					required: true
				},
				"productVO.productModel.price" : {
					required: true,
					money: true
				},
				"productVO.productModel.phone" : {
					required: true,
					phoneNumber2 : true,
					byteRangeLength : [1,20]
				},
				"productVO.productModel.startAddress" : {
					required: true
				},
				"productVO.productModel.destination" : {
					required: true
				},
				"productVO.headImage.file" : {
					<s:if test='"create".equals(#request.actionType)'>
					required: true,
					</s:if>
					fileExtName : "jpg,gif,png",
					validateFileSize : 2000000
				},
				"productVO.productModel.serviceProvider" : {
					required: true
				},
				"#startintDate_0" : {
					required: true,
					dateformat: true
				},
				"#startintDate_1" : {
					required: true,
					dateformat: true
				},
				"#startintDate_2" : {
					required: true,
					dateformat: true
				},
				"#startintDate_3" : {
					required: true,
					dateformat: true
				},
				"#startintDate_4" : {
					required: true,
					dateformat: true
				},
				"product_images" : {
					checkProductImages: true
				},
				"productVO.productModel.productFeatures" : {
					required : true
				},
				"#product_productImages_0" : {
					checkProductImages: true,
					fileExtName : "jpg,gif,png",
					validateFileSize : 2000000
				},
				"#product_productImages_1" : {
					checkProductImages: true,
					fileExtName : "jpg,gif,png",
					validateFileSize : 2000000
				},
				"#product_productImages_2" : {
					checkProductImages: true,
					fileExtName : "jpg,gif,png",
					validateFileSize : 2000000
				},
				"#product_productImages_3" : {
					checkProductImages: true,
					fileExtName : "jpg,gif,png",
					validateFileSize : 2000000
				},
				"#product_productImages_4" : {
					checkProductImages: true,
					fileExtName : "jpg,gif,png",
					validateFileSize : 2000000
				},
				"#adminStory_0_title" : {
					required: true
				},
				"#adminStory_1_title" : {
					required: true
				},
				"#adminStory_2_title" : {
					required: true
				},
				"#adminStory_3_title" : {
					required: true
				},
				"#adminStory_4_title" : {
					required: true
				}
			},
			messages: {
				"productVO.productModel.productCategoryModel.id" : {
					required: "请选择类型！"
				},
				"productVO.productModel.fullName" : {
					required: "请输入主题"
				},
				"productVO.productModel.price" : {
					required: "请输入价格",
					money: "请输入正确金额"
				},
				"productVO.productModel.phone" : {
					required: "请输入联系电话",
					phoneNumber2: "请输入正确号码",
					byteRangeLength: "请输入正确号码"
				},
				"productVO.productModel.startAddress" : {
					required: "请选择出发地"
				},
				"productVO.productModel.destination" : {
					required: "请选择目的地"
				},
				"productVO.headImage.file" : {
					<s:if test='"create".equals(#request.actionType)'>
					required: "请上传商品图片",
					</s:if>
					fileExtName : "请上传jpg,gif,png文件",
					validateFileSize : "文件大小不能超过2M"
				},
				"productVO.productModel.serviceProvider" : {
					required: "请输入服务提供商"
				},
				"#startintDate_0" : {
					required: "请输入出发时间"
				},
				"#startintDate_1" : {
					required: "请输入出发时间"
				},
				"#startintDate_2" : {
					required: "请输入出发时间"
				},
				"#startintDate_3" : {
					required: "请输入出发时间"
				},
				"#startintDate_4" : {
					required: "请输入出发时间"
				},
				"productVO.productModel.productFeatures" : {
					required : "请输入产品特色"
				},
				"#product_productImages_0" : {
					checkProductImages: "请上传产品轮播图",
					fileExtName : "请上传jpg,gif,png文件",
					validateFileSize : "文件大小不能超过2M"
				},
				"#product_productImages_1" : {
					checkProductImages: "请上传产品轮播图",
					fileExtName : "请上传jpg,gif,png文件",
					validateFileSize : "文件大小不能超过2M"
				},
				"#product_productImages_2" : {
					checkProductImages: "请上传产品轮播图",
					fileExtName : "请上传jpg,gif,png文件",
					validateFileSize : "文件大小不能超过2M"
				},
				"#product_productImages_3" : {
					checkProductImages: "请上传产品轮播图",
					fileExtName : "请上传jpg,gif,png文件",
					validateFileSize : "文件大小不能超过2M"
				},
				"#product_productImages_4" : {
					checkProductImages: "请上传产品轮播图",
					fileExtName : "请上传jpg,gif,png文件",
					validateFileSize : "文件大小不能超过2M"
				},
				"#adminStory_0_title" : {
					required: "请输入题目"
				},
				"#adminStory_1_title" : {
					required: "请输入题目"
				},
				"#adminStory_2_title" : {
					required: "请输入题目"
				},
				"#adminStory_3_title" : {
					required: "请输入题目"
				},
				"#adminStory_4_title" : {
					required: "请输入题目"
				}
			},
			
			invalidHandler: function (event, validator) { //display error alert on form submit   
				$('.alert-danger', $('.login-form')).show();
			},
	
			highlight: function (e) {
				$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
			},
	
			success: function (e) {
				$(e).closest('.form-group').removeClass('has-error').addClass('has-info');
				$(e).remove();
			},
	
			errorPlacement: function (error, element) {
				if(element.is(':checkbox') || element.is(':radio')) {
					var controls = element.closest('div[class*="col-"]');
					if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
					else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
				} else if(element.is('.select2')) {
					error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
				} else if(element.is('.chosen-select')) {
					error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
				} else error.insertAfter(element.parent());
			}//,
	
			//submitHandler: function (form) {
				//$(form).submit();
			//},
			//invalidHandler: function (form) {
			//}
		});
	});
	function init_ace_file_input(filterString) {
		$(filterString).ace_file_input({
			no_file:'No File ...',
			btn_choose:'Choose',
			btn_change:'Change',
			droppable:false,
			onchange:null,
			thumbnail:false //| true | large
			//whitelist:'gif|png|jpg|jpeg',
			//blacklist:'exe|php'
			//onchange:''
			//
		});
	}
	function init_ace_wysiwyg(filterString) {
		$(filterString).ace_wysiwyg({
			toolbar:
				[
					'font',
					null,
					'fontSize',
					null,
					{name:'bold', className:'btn-info'},
					{name:'italic', className:'btn-info'},
					{name:'strikethrough', className:'btn-info'},
					{name:'underline', className:'btn-info'},
					null,
					{name:'insertunorderedlist', className:'btn-success'},
					{name:'insertorderedlist', className:'btn-success'},
					{name:'outdent', className:'btn-purple'},
					{name:'indent', className:'btn-purple'},
					null,
					{name:'justifyleft', className:'btn-primary'},
					{name:'justifycenter', className:'btn-primary'},
					{name:'justifyright', className:'btn-primary'},
					{name:'justifyfull', className:'btn-inverse'},
					null,
					{name:'createLink', className:'btn-pink'},
					{name:'unlink', className:'btn-pink'},
					null,
					{name:'insertImage', className:'btn-success'},
					null,
					'foreColor',
					null,
					{name:'undo', className:'btn-grey'},
					{name:'redo', className:'btn-grey'}
				],
				'wysiwyg': {
					fileUploadError: showErrorAlert
				}
			}).prev().addClass('wysiwyg-style2');
	}
	function showErrorAlert (reason, detail) {
		var msg='';
		if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
		else {
			console.log("error uploading file", reason, detail);
		}
		$('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+ 
		 '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
	}
	function deleteProductItem(index) {
		$('#accordion_productItems_' + index).remove();
		refreshProductItemIndex();
	}
	function refreshProductItemIndex() {
		var items = $('#productItems_div span[class="product_item_title"]');
		if(items != null && items.length > 0) {
			for(var i = 0; i < items.length; i ++) {
				$(items[i]).html('#' + (i + 1));
			}
		}
	}
	/*
	var productItems_num = -1;
	function addProductItems() {
		productItems_num ++;
		var re = new RegExp("LY","g");
		var re1 = new RegExp("LY_1", "g");
		$('#productItems_div').append($('#productItems_example').html().replace(re1, productItems_num + 1).replace(re, productItems_num));
		init_ace_wysiwyg('#productItem_' + productItems_num + '_introduction_div');
		refreshProductItemIndex();
	}*/
	/*
	var adminStorys_num = -1;
	function addAdminStorys() {
		adminStorys_num ++;
		var re = new RegExp("LY","g");
		var re1 = new RegExp("LY_1", "g");
		$('#adminStorys_div').append($('#adminStorys_example').html().replace(re1, adminStorys_num + 1).replace(re, adminStorys_num));
		init_ace_wysiwyg('#adminStory_' + adminStorys_num + '_content_div');
	}*/
	// select 特效框赋值
	function initS2Info(id, value, text) {
		//$('#product_type option[value="<s:property value="productVO.productModel.productType.productTypeId" />"]').attr('selected', true);
		//$('#s2id_product_type a[class="select2-choice"] span[class="select2-chosen"]').html('<s:property value="productVO.productModel.productType.productTypeName" />');
		$('#' + id + ' option[value="' + value + '"]').attr('selected', true);
		$('#s2id_' + id + ' a[class="select2-choice"] span[class="select2-chosen"]').html(text);
	}
	</script>
	<s:if test='"create".equals(#request.actionType)'>
		<script type="text/javascript">
		jQuery(function($) {
			$('#csc_product_edit_form').attr('action', 'product/createProduct.action');
			$('#product_serviceProvider').attr('value', '<s:property value="#session.AgentProfile.adminModel.serviceProvider" />');
		});
		</script>
	</s:if>
	<s:elseif test='"update".equals(#request.actionType)'>
		<script type="text/javascript">
		jQuery(function($) {
			/** step1 start */
			$('#csc_product_edit_form').attr('action', 'product/updateProduct.action');
			initS2Info('product_category', '<s:property value="productVO.productModel.productCategoryModel.id" />', '<s:property value="productVO.productModel.productCategoryModel.name" />');
			$('#product_fullName').attr('value', '<s:property value="productVO.productModel.fullName" />');
			$('#product_price').attr('value', '<s:property value="productVO.productModel.price" />');
			$('#product_childrenPrice').attr('value', '<s:property value="productVO.productModel.childrenPrice" />');
			$('#product_hoursePrice').attr('value', '<s:property value="productVO.productModel.hoursePrice" />');
			$('#product_phone').attr('value', '<s:property value="productVO.productModel.phone" />');
			initS2Info('product_startAddress', '<s:property value="productVO.productModel.startAddress" />', '<s:property value="productVO.productModel.startAddress" />');
			initS2Info('product_destination', '<s:property value="productVO.productModel.destination" />', '<s:property value="productVO.productModel.destination" />');
			$('#product_serviceProvider').attr('value', '<s:property value="productVO.productModel.serviceProvider" />');
			$('#product_isMarketable').attr('value', '<s:property value="productVO.productModel.isMarketable" />');
			var isMarketable = '<s:property value="productVO.productModel.isMarketable" />';
			if(isMarketable != null && isMarketable) {
				$('#product_isMarketable_box').click();
			}
			$('#product_isTop').attr('value', '<s:property value="productVO.productModel.isTop" />');
			var isTop = '<s:property value="productVO.productModel.isTop" />';
			if(isTop != null && isTop) {
				$('#product_isTop_box').click();
			}
			$('#product_startingDate').attr('value', '<s:property value="productVO.productModel.startingDate" />');
			var startingDate = '<s:property value="productVO.productModel.startingDate" />';
			if($.trim(startingDate) != '') {
				var dates = new Array();
				if(startingDate.length == 'yyyy-MM-dd'.length) {
					dates[0] = startingDate;
				} else {
					dates = startingDate.split(',');
				}
				for(var i = 0; i < dates.length; i++) {
					addStartingDate();
					$('#startingDate_' + i).val(dates[i]);
				}
			}
			$('#product_introduction_div').html($('#update_product_introduction_div').html());
			$('#product_productFeatures_div').html($('#update_product_productFeatures_div').html());
			$('#product_feeInclude_div').html($('#update_product_feeInclude_div').html());
			/** step1 end */
			/** step2 start */
			$('#product_introduction1_div').html($('#update_product_introduction1_div').html());
			$('#product_visaInfo_div').html($('#update_product_visaInfo_div').html());
			$('#product_flightInfo_div').html($('#update_product_flightInfo_div').html());
			$('#product_hotelInfo_div').html($('#update_product_hotelInfo_div').html());
			$('#product_feeInclude1_div').html($('#update_product_feeInclude1_div').html());
			/** step2 end */
			
		});
		</script>
		<s:if test='productVO.productTags != null && productVO.productTags.size() > 0'>
			<script type="text/javascript">
			jQuery(function($) {
			<s:iterator value="productVO.productTags" var="productTagItem">
				<s:if test='#productTagItem.tagModel.mdisplayInfo == 0'>
					$('#imageHead_<s:property value="#productTagItem.tagModel.id" />').attr('checked', 'checked');
				</s:if>
				<s:elseif test='#productTagItem.tagModel.mdisplayInfo == 1'>
					$('#descInfo_<s:property value="#productTagItem.tagModel.id" />').attr('checked', 'checked');
				</s:elseif>
			</s:iterator>
			});
			</script>
		</s:if>
		<%-- 
		<s:if test='productVO.productItems != null && productVO.productItems.size() > 0'>
			<script type="text/javascript">
			/** step2 start */
			<s:iterator value="productVO.productItems" var="productItem" status="countIdx">
			jQuery(function($) {
				addProductItems();
				$('#productItem_<s:property value="#countIdx.index" />_id').attr('value', '<s:property value="#productItem.id" />');
				$('#productItem_<s:property value="#countIdx.index" />_traffic').attr('value', '<s:property value="#productItem.traffic" />');
				$('#productItem_<s:property value="#countIdx.index" />_stay').attr('value', '<s:property value="#productItem.stay" />');
				$('#productItem_<s:property value="#countIdx.index" />_repast').attr('value', '<s:property value="#productItem.repast" />');
				$('#productItem_<s:property value="#countIdx.index" />_startAddress').attr('value', '<s:property value="#productItem.startAddress" />');
				$('#productItem_<s:property value="#countIdx.index" />_destination').attr('value', '<s:property value="#productItem.destination" />');
				$('#productItem_<s:property value="#countIdx.index" />_introduction_div').html($('#update_productItem_<s:property value="#countIdx.index" />_introduction_div').html());
			});
			</s:iterator>
			/** step2 end */
			</script>
		</s:if>
		 --%>
		<%--
		<s:if test='productVO.adminStorys != null && productVO.adminStorys.size() > 0'>
			<script type="text/javascript">
			/** step3 start */
			<s:iterator value="productVO.adminStorys" var="adminStory" status="countIdx">
			jQuery(function($) {
				addAdminStorys();
				$('#adminStory_<s:property value="#countIdx.index" />_id').attr('value', '<s:property value="#adminStory.id" />');
				$('#adminStory_<s:property value="#countIdx.index" />_title').attr('value', '<s:property value="#adminStory.title" />');
				
			});
			</s:iterator>
			/** step3 end */
			</script>
		</s:if>
		--%>
	</s:elseif>
</s:if>
<s:elseif test="productVO.productModel.mproductType == 1">
	<script type="text/javascript">
	jQuery(function($) {
		$(".select2").css('width','200px').select2({allowClear:true}).on('change', function(){
			$(this).closest('form').validate().element($(this));
		});
		
		init_ace_file_input('#product_image , .product_productImages');
		
		init_ace_wysiwyg('#product_productFeatures_div');
		init_ace_wysiwyg('#product_introduction_div');
		init_ace_wysiwyg('#product_introduction1_div');
		init_ace_wysiwyg('#product_feeInclude_div');
		init_ace_wysiwyg('#product_feeInclude1_div');
		
		init_ace_checkbox('product_isMarketable');
		//init_ace_checkbox('product_isTop');
		
		function validStartingDate() {
			if(startingDate_num < 0) {
				addStartingDate();
				$('#startingDate_0').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			var startingDate_str = '';
			for(var i = 0; i <= startingDate_num; i ++) {
				if($.trim($('#startingDate_' + i).val()) != '') {
					if(startingDate_str != '') {
						startingDate_str += ',';
					}
					startingDate_str += $('#startingDate_' + i).val();
				}
			}
			if($.trim(startingDate_str) != '') {
				$('#product_startingDate').attr('value', startingDate_str);
				$('#startingDate_0').closest('.form-group').removeClass('has-error').addClass('has-info');
				return true;
			}
			$('#startingDate_0').closest('.form-group').removeClass('has-info').addClass('has-error');
			return false;
		}
		function validProductImages() {
		<s:if test='"create".equals(#request.actionType)'>
			if(productImages_num < 0) {
				addProductImages();
				$('#product_productImages_0').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			var hasImages = false;
			for(var i = 0; i <= productImages_num; i++) {
				if($('#product_productImages_' + i).val() != null) {
					$('#product_productImages_0').closest('.form-group').removeClass('has-error').addClass('has-info');
					hasImages = hasImages || true;
				} else {
					hasImages = hasImages || false;
				}
			}
			return hasImages;
		</s:if>
		<s:else>
			return true;
		</s:else>
		}
		
		function validPriceItems() {
			if(priceItems_num < 0) {
				addPriceItems();
				$('#priceItem_0_name').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			var hasPriceItem = false;
			var hasIntroduction = true;
			for(var i = 0; i <= priceItems_num; i ++) {
				if($('#accordion_priceItems_' + i).html()) {
					hasPriceItem = hasPriceItem || true;
					var html = $('#priceItem_' + i + '_name').val();
					if($.trim(html) == '') {
						$('#priceItem_' + i + '_name').closest('.form-group').removeClass('has-info').addClass('has-error');
						hasIntroduction = hasIntroduction && false;
					} else {
						$('#priceItem_' + i + '_name').closest('.form-group').removeClass('has-error').addClass('has-info');
					}
				}
			}
			
			if(!hasPriceItem) {
				addPriceItems();
				$('#priceItem_0_name').closest('.form-group').removeClass('has-info').addClass('has-error');
				return false;
			}
			//alert(hasPriceItem + ", " + hasIntroduction);
			return hasIntroduction && hasPriceItem;
		}
		
		var $validation = true;
		$('#fuelux-wizard').ace_wizard().on('change' , function(e, info){
			if(info.step == 1 && $validation) {
				// step 1
				var validResult = $('#csc_product_edit_form').valid();
				validResult = validStartingDate() && validResult;
				validResult = validProductImages() && validResult;
				if(!validResult) {
					return false;
				} else {
					if(priceItems_num < 0) {
						addPriceItems();
					}
					return true;
				}
			} else if(info.step == 2 && $validation) {
				// step 2
				if(validPriceItems()) {
					return true;
				} else {
					return false;
				}
			}
		}).on('finished', function(e) {
			//$('#csc_product_search_form').submit();
			// 拼装StartingDate
			//product_startingDate
			if(startingDate_num < 0) {
				alert("请输入出发时间！");
				return false;
			}
			<s:if test='"create".equals(#request.actionType)'>
			if(productImages_num < 0) {
				alert("请最少上传一张轮播图！");
				return false;
			}
			</s:if>
			// 处理Step1富文本编辑器
			$('#product_productFeatures').text($('#product_productFeatures_div').html());
			$('#product_introduction').text($('#product_introduction_div').html());
			$('#product_introduction1').text($('#product_introduction1_div').html());
			$('#product_feeInclude').text($('#product_feeInclude_div').html());
			$('#product_feeInclude1').text($('#product_feeInclude1_div').html());
			// 提交表单
			$('#csc_product_edit_form').submit();
		}).on('stepclick', function(e){
			alert(e);
			//return false;//prevent clicking on steps
		});
		
		$.validator.methods.checkStartingDate = function(value, element, param){
			return validStartingDate();
		};
		
		$.validator.methods.checkProductImages = function(value, element, param){
			return validProductImages();
		};
		
		$('#csc_product_edit_form').validate({
			errorElement: 'div',
			errorClass: 'help-block',
			focusInvalid: false,
			rules: {
				"productVO.productModel.productCategoryModel.id" : {
					required: true
				},
				"productVO.productModel.fullName" : {
					required: true
				},
				"productVO.productModel.price" : {
					required: true,
					money: true
				},
				"productVO.productModel.phone" : {
					required: true,
					phoneNumber2 : true,
					byteRangeLength : [1,20]
				},
				"productVO.headImage.file" : {
					<s:if test='"create".equals(#request.actionType)'>
					required: true,
					</s:if>
					fileExtName : "jpg,gif,png",
					validateFileSize : 2000000
				},
				"productVO.productModel.serviceProvider" : {
					required: true
				}
			},
			messages: {
				"productVO.productModel.productCategoryModel.id" : {
					required: "请选择类型！"
				},
				"productVO.productModel.fullName" : {
					required: "请输入主题"
				},
				"productVO.productModel.price" : {
					required: "请输入价格",
					money: "请输入正确金额"
				},
				"productVO.productModel.phone" : {
					required: "请输入联系电话",
					phoneNumber2: "请输入正确号码",
					byteRangeLength: "请输入正确号码"
				},
				"productVO.headImage.file" : {
					<s:if test='"create".equals(#request.actionType)'>
					required: "请上传商品图片",
					</s:if>
					fileExtName : "请上传jpg,gif,png文件",
					validateFileSize : "文件大小不能超过2M"
				},
				"productVO.productModel.serviceProvider" : {
					required: "请输入服务提供商"
				}
			},
			
			invalidHandler: function (event, validator) { //display error alert on form submit   
				$('.alert-danger', $('.login-form')).show();
			},
	
			highlight: function (e) {
				$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
			},
	
			success: function (e) {
				$(e).closest('.form-group').removeClass('has-error').addClass('has-info');
				$(e).remove();
			},
	
			errorPlacement: function (error, element) {
				if(element.is(':checkbox') || element.is(':radio')) {
					var controls = element.closest('div[class*="col-"]');
					if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
					else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
				}
				else if(element.is('.select2')) {
					error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
				}
				else if(element.is('.chosen-select')) {
					error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
				}
				else error.insertAfter(element.parent());
			}//,
	
			//submitHandler: function (form) {
				//$(form).submit();
			//},
			//invalidHandler: function (form) {
			//}
		});
	});
	function init_ace_file_input(filterString) {
		$(filterString).ace_file_input({
			no_file:'No File ...',
			btn_choose:'Choose',
			btn_change:'Change',
			droppable:false,
			onchange:null,
			thumbnail:false //| true | large
			//whitelist:'gif|png|jpg|jpeg',
			//blacklist:'exe|php'
			//onchange:''
			//
		});
	}
	function init_ace_wysiwyg(filterString) {
		$(filterString).ace_wysiwyg({
			toolbar:
				[
					'font',
					null,
					'fontSize',
					null,
					{name:'bold', className:'btn-info'},
					{name:'italic', className:'btn-info'},
					{name:'strikethrough', className:'btn-info'},
					{name:'underline', className:'btn-info'},
					null,
					{name:'insertunorderedlist', className:'btn-success'},
					{name:'insertorderedlist', className:'btn-success'},
					{name:'outdent', className:'btn-purple'},
					{name:'indent', className:'btn-purple'},
					null,
					{name:'justifyleft', className:'btn-primary'},
					{name:'justifycenter', className:'btn-primary'},
					{name:'justifyright', className:'btn-primary'},
					{name:'justifyfull', className:'btn-inverse'},
					null,
					{name:'createLink', className:'btn-pink'},
					{name:'unlink', className:'btn-pink'},
					null,
					{name:'insertImage', className:'btn-success'},
					null,
					'foreColor',
					null,
					{name:'undo', className:'btn-grey'},
					{name:'redo', className:'btn-grey'}
				],
				'wysiwyg': {
					fileUploadError: showErrorAlert
				}
			}).prev().addClass('wysiwyg-style2');
	}
	function showErrorAlert (reason, detail) {
		var msg='';
		if (reason==='unsupported-file-type') {
			msg = "Unsupported format " +detail;
		} else {
			console.log("error uploading file", reason, detail);
		}
		$('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+ 
		 '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
	}
	function deletePriceItem(index) {
		$('#accordion_priceItems_' + index).remove();
		refreshPriceItemIndex();
	}
	var priceItems_num = -1;
	function addPriceItems() {
		priceItems_num ++;
		var re = new RegExp("LY","g");
		var re1 = new RegExp("LY_1", "g");
		$('#priceItems_div').append($('#priceItems_example').html().replace(re1, priceItems_num + 1).replace(re, priceItems_num));
		init_ace_checkbox('priceItem_' + priceItems_num + '_isAvailable');
		// 添加校验
		$('#priceItem_' + priceItems_num + '_name').rules("add", {required : true, messages : {required:"此项必填"}}); 
		$('#priceItem_' + priceItems_num + '_price').rules("add", {required : true, number : true, messages:{required : "此项必填", number : "仅能为数字！"}});
		$('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});
		refreshPriceItemIndex();
	}
	function refreshPriceItemIndex() {
		var items = $('#priceItems_div span[class="price_item_title"]');
		if(items != null && items.length > 0) {
			for(var i = 0; i < items.length; i ++) {
				$(items[i]).html('#' + (i + 1));
			}
		}
	}
	// select 特效框赋值
	function initS2Info(id, value, text) {
		//$('#product_type option[value="<s:property value="productVO.productModel.productType.productTypeId" />"]').attr('selected', true);
		//$('#s2id_product_type a[class="select2-choice"] span[class="select2-chosen"]').html('<s:property value="productVO.productModel.productType.productTypeName" />');
		$('#' + id + ' option[value="' + value + '"]').attr('selected', true);
		$('#s2id_' + id + ' a[class="select2-choice"] span[class="select2-chosen"]').html(text);
	}
	</script>
	<s:if test='"create".equals(#request.actionType)'>
		<script type="text/javascript">
		jQuery(function($) {
			$('#csc_product_edit_form').attr('action', 'product/createProduct.action');
			$('#product_serviceProvider').attr('value', '<s:property value="#session.AgentProfile.adminModel.serviceProvider" />');
		});
		</script>
	</s:if>
	<s:elseif test='"update".equals(#request.actionType)'>
		<script type="text/javascript">
		jQuery(function($) {
			/** step1 start */
			$('#csc_product_edit_form').attr('action', 'product/updateProduct.action');
			initS2Info('product_category', '<s:property value="productVO.productModel.productCategoryModel.id" />', '<s:property value="productVO.productModel.productCategoryModel.name" />');
			$('#product_fullName').attr('value', '<s:property value="productVO.productModel.fullName" />');
			$('#product_price').attr('value', '<s:property value="productVO.productModel.price" />');
			$('#product_childrenPrice').attr('value', '<s:property value="productVO.productModel.childrenPrice" />');
			$('#product_hoursePrice').attr('value', '<s:property value="productVO.productModel.hoursePrice" />');
			$('#product_phone').attr('value', '<s:property value="productVO.productModel.phone" />');
			$('#product_startAddress').attr('value', '<s:property value="productVO.productModel.startAddress" />');
			$('#product_destination').attr('value', '<s:property value="productVO.productModel.destination" />');
			$('#product_serviceProvider').attr('value', '<s:property value="productVO.productModel.serviceProvider" />');
			$('#product_isMarketable').attr('value', '<s:property value="productVO.productModel.isMarketable" />');
			var isMarketable = '<s:property value="productVO.productModel.isMarketable" />';
			if(isMarketable != null && isMarketable) {
				$('#product_isMarketable_box').click();
			}
			$('#product_isTop').attr('value', '<s:property value="productVO.productModel.isTop" />');
			$('#product_startingDate').attr('value', '<s:property value="productVO.productModel.startingDate" />');
			var startingDate = '<s:property value="productVO.productModel.startingDate" />';
			if($.trim(startingDate) != '') {
				var dates = new Array();
				if(startingDate.length == 'yyyy-MM-dd'.length) {
					dates[0] = startingDate;
				} else {
					dates = startingDate.split(',');
				}
				for(var i = 0; i < dates.length; i++) {
					addStartingDate();
					$('#startingDate_' + i).val(dates[i]);
				}
			}
			$('#product_productFeatures_div').html($('#update_product_productFeatures_div').html());
			$('#product_introduction_div').html($('#update_product_introduction_div').html());
			$('#product_introduction1_div').html($('#update_product_introduction1_div').html());
			$('#product_feeInclude_div').html($('#update_product_feeInclude_div').html());
			$('#product_feeInclude1_div').html($('#update_product_feeInclude1_div').html());
			/** step1 end */
		});
		</script>
		<s:if test='productVO.priceItemModels != null && productVO.priceItemModels.size() > 0'>
			<script type="text/javascript">
			/** step2 start */
			<s:iterator value="productVO.priceItemModels" var="priceItem" status="countIdx">
			jQuery(function($) {
				addPriceItems();
				$('#priceItem_<s:property value="#countIdx.index" />_id').attr('value', '<s:property value="#priceItem.id" />');
				$('#priceItem_<s:property value="#countIdx.index" />_name').attr('value', '<s:property value="#priceItem.name" />');
				$('#priceItem_<s:property value="#countIdx.index" />_price').attr('value', '<s:property value="#priceItem.price" />');
				$('#priceItem_<s:property value="#countIdx.index" />_availableStartDate').attr('value', '<s:property value="#priceItem.availableStartDate" />');
				$('#priceItem_<s:property value="#countIdx.index" />_availableEndDate').attr('value', '<s:property value="#priceItem.availableEndDate" />');
				$('#priceItem_<s:property value="#countIdx.index" />_isAvailable').attr('value', '<s:property value="#priceItem.isAvailable" />');
				var isAvailable = '<s:property value="#priceItem.isAvailable" />';
				if(isAvailable != null && isAvailable) {
					$('#priceItem_<s:property value="#countIdx.index" />_isAvailable_box').click();
				}
			});
			</s:iterator>
			/** step2 end */
			</script>
		</s:if>
	</s:elseif>
</s:elseif>
</body>
</html>